const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const OpenBrowserPlugin = require('open-browser-webpack-plugin');
const path = require('path');
const domainPath = require('../conf/dev.config');


process.noDeprecation = true;

module.exports = {
    entry: {
        app: [path.join(__dirname, '../public/src/App.js'), 'webpack-hot-middleware/client'],
        common: ['react', 'react-dom', 'dva']
    },
    devtool: 'source-map',
    output: {
        path: path.join(__dirname, "../public/dist/"),
        filename: 'js/[name].js',
        chunkFilename: 'js/[name].chunk.js',
        publicPath: '/'
    },
    resolve: {
        // require文件的时候不需要写后缀了，可以自动补全
        extensions: ['.js', '.jsx', '.css', '.scss']
    },
    module: {
        rules: [{
            test: /\.(js|jsx)$/,
            exclude: /(node_modules)/,
            use: [{
                loader: 'babel-loader',
                options: {
                    cacheDirectory: true,
                    presets: ['es2015', 'react'],
                    plugins: [
                        ["import", {libraryName: "antd", style: "css"}],
                        ["transform-runtime"],
                        ["transform-class-properties"],
                        ["transform-async-to-generator"],
                        ["transform-object-rest-spread"]
                    ]
                }
            }]
        },
            {test: /\.css$/, loader: 'style-loader!css-loader'},
            {
                test: /\.((ttf|eot|woff|svg)(\?t=[0-9]\.[0-9]\.[0-9]))|(ttf|eot|woff|svg)\??.*$/,
                loader: 'url-loader',
                options: {
                    limit: 10000,
                    name: 'iconfont/[name].[ext]'
                }
            },
            {
                test: /\.(png|jpg|gif)$/,
                loader: 'url-loader',
                options: {
                    limit: 10000,
                    name: 'images/[name].[ext]'
                }
            }]
    },
    plugins: [
        new OpenBrowserPlugin({url: domainPath.cdnPath}),
        new webpack.optimize.CommonsChunkPlugin({
            filename: "js/common.js",
            name: "common"
        }),
        new webpack.HotModuleReplacementPlugin(),
        new webpack.NoEmitOnErrorsPlugin(),
        new HtmlWebpackPlugin({
            filename: '../../views/index.ejs',
            hash: true,
            template: 'public/src/views/index.ejs',
            // apiPath: 'http://localhost:3334'
        })
    ]
};
